package com.jsy.common.leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

class MinStack {

    private Stack<Integer> stack;
    private Stack<Integer> minStack;

    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }
    
    public void push(int val) {
        stack.push(val);
        minStack.push(Math.min(val,minStack.peek()));
    }
    
    public void pop() {
        if (!stack.isEmpty()){
            stack.pop();
            minStack.pop();
        }
    }
    
    public int top() {
       return stack.peek();
    }
    
    public int getMin() {
       if (minStack.isEmpty()){
           return -1;
       }
       return minStack.peek();
    }
}